import functools
from flask import current_app
from flask import g
from flask import session

from info.models import User


def do_index_class(index):
    if index == 1:
        return 'first'
    if index == 2:
        return 'second'
    if index == 3:
        return 'third'
    else:
        return ''


def get_login_info(fun):
    @functools.wraps(fun)
    def call_fun(*agrs, **kwargs):
        user_id = session.get('user_id')
        user = None
        if user_id:
            try:
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user = user
        return fun(*agrs, **kwargs)

    return call_fun
